package Leetcode.array;

public class Twosinglename {
     //num1,num2分别为长度为L的数组。传出参数
    //将num1[0],num2[0]设置为返回结果
        public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) {
            int t=singleNumber(array);

            int index=0;
            while ((t&1)!=1){
                t=t>>1;
                index++;
            }


            for(int j=0;j<array.length;j++){
              if (isbit(array[j],index)){
                 // System.out.println("[1]^:"+array[j]);
                 // System.out.println("1:"+num1[0]);
                  num1[0]=num1[0]^array[j];
              }
              else {
                 // System.out.println("[2]^:"+array[j]);
                 // System.out.println("2:"+num2[0]);
                  num2[0] =num2[0]^array[j];

              }
            }
        }

        public int singleNumber(int[] nums) {
            int t=nums[0];
            for(int i=1;i<nums.length;i++){
                 t=t^nums[i];
            }
             return t;
        }

        public boolean isbit(int num,int index){
             num=num>>index;
             if((num&1)==1)
                 return true;
             else
                 return false;
        }

    public static void main(String[] args) {
            int[] a={2,4,3,6,3,2,5,5};
            int length=a.length;
            int[] num1=new  int[length];
            int[] num2=new  int[length];;
            Twosinglename solution2=new Twosinglename();
            solution2.FindNumsAppearOnce(a,num1,num2);

        System.out.println(num1[0]);
        System.out.print(num2[0]);

    }
}
